import os
import datetime
from google.appengine.ext        import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
from models.invoice              import Invoice
from services.invoice            import InvoiceService
from services.personal           import PersonalService
from services.company            import CompanyService
from services.home               import HomeService
from services.tools              import ToolsService
from   xml.etree import ElementTree

class MainHandler(webapp.RequestHandler):
	def post(self):
		pass
	def get(self):
		#http://pleac.sourceforge.net/pleac_python/datesandtimes.html
		path = os.path.join(os.path.dirname(__file__), 'views/index.html')
		html = template.render(path, {})
		self.response.out.write(html)

def main():
    application = webapp.WSGIApplication([('/', MainHandler),
		('/services/personal',              PersonalService.Index),
		('/services/companies/update/(.*)', CompanyService.Update),
		('/services/companies/delete/(.*)', CompanyService.Delete),
		('/services/companies/create',      CompanyService.Create),
		('/services/companies',             CompanyService.Index),	
		('/services/invoices/update/(.*)',  InvoiceService.Update),
		('/services/invoices/delete/(.*)',  InvoiceService.Delete),
	    ('/services/invoices/open/(.*)',    InvoiceService.Open),
		('/services/invoices/create',       InvoiceService.Create),
		('/services/invoices',              InvoiceService.Index),
		('/services/home',                  HomeService.Index),
		('/services/tools',                 ToolsService.Index),
		('/services/tools/computetax',      ToolsService.ComputeTax),
		('/services/tools/appdata',         ToolsService.AppData),
		('/services/tools/emailbackup',     ToolsService.EmailBackup)
	],
                                         debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
